﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Aribaccio;
using Aribaccio.Datum;
using BDPAutodetect.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace BDPAutodetect.DataService
{
    public class TTargetSlaveConfiguration : TBaseConfiguration, IEntityTypeConfiguration<TTargetSlave>
    {
        /// 构造函数
        /// </summary>
        public TTargetSlaveConfiguration(DBConnectType argConnectionType)
            : base(argConnectionType)
        {

        }

        /// <summary>
        /// 配置映射关系
        /// </summary>
        /// <param name="builder"></param>
        public void Configure(EntityTypeBuilder<TTargetSlave> builder)
        {
            builder.ToTable("T_Target_Slave");
            builder.Property(e => e.ID).HasColumnName("ID");
            builder.HasIndex(e => new { e.StationID, e.SlaveID, e.TargetID, e.Category }, "UQ_T_Target_Slave").IsUnique();
            switch (this.ConnectionType)
            {
                case DBConnectType.SQLServer:
                    break;
                case DBConnectType.PostgreSQL:
                    builder.Property(e => e.Category).HasDefaultValue(0);
                    builder.Property(e => e.SlaveID).HasDefaultValue(0).HasColumnName("SlaveID");
                    builder.Property(e => e.StationID).HasDefaultValue(0).HasColumnName("StationID");
                    builder.Property(e => e.TargetID).HasDefaultValue(0).HasColumnName("TargetID");
                    builder.Property(e => e.TargetMapID).HasDefaultValue(0).HasColumnName("TargetMapID");
                    builder.Property(e => e.SlaveCommand).HasColumnType("character varying");
                    builder.Property(e => e.CheckCommand).HasColumnType("character varying");                    
                    builder.Property(e => e.SlaveAddress).HasDefaultValue(0);
                    builder.Property(e => e.SlaveFuncCode).HasDefaultValue(0);
                    builder.Property(e => e.RegisterAddress).HasDefaultValue(0);
                    builder.Property(e => e.CheckMode).HasDefaultValue(0);
                    builder.Property(e => e.DataType).HasDefaultValue(0);
                    builder.Property(e => e.DataUnit).HasDefaultValue(0);
                    builder.Property(e => e.DisplayUnit).HasDefaultValue(0);
                    builder.Property(e => e.SendWaitFlag).HasDefaultValue(0);
                    builder.Property(e => e.DetectWaitFlag).HasDefaultValue(0);
                    builder.Property(e => e.PermissionFlag).HasDefaultValue(0);
                    builder.Property(e => e.UpdateTime).HasDefaultValueSql("now()").HasColumnType("timestamp without time zone");
                    break;
            }
        }
    }
}
